cd "/Users/s.abi-hassan/Dropbox/OSU_WashU_NU Research Team/Downstream_cert/Replication_file"

use "justice86F_cert.dta", clear

* Table 1 - Sumary Statistics
estpost 
summarize bi_choicedv bi_certVote certDumb1 iddistance legalScores legalSalience ///
pubSalience resCoop frosh chiefJustice num_totBriefs dich_bcentTot dich_totsic
	
********************************************************
*Logistic Regression Models
********************************************************
*base model
logit bi_choicedv bi_certVote iddistance legalScores legalSalience ///
pubSalience resCoop frosh chiefJustice i.certDumb1 ///
i.term i.issueArea, vce(cluster justiceName)
estat ic
eststo model1

*Number of Amicus Brifs
logit bi_choicedv bi_certVote iddistance legalScores legalSalience ///
pubSalience resCoop frosh chiefJustice i.certDumb1 ///
num_totBriefs i.term i.issueArea , vce(cluster justiceName)
estat ic
eststo model2

*Amici Power
logit bi_choicedv bi_certVote iddistance legalScores legalSalience ///
pubSalience resCoop frosh chiefJustice i.certDumb1 ///
dich_bcentTot i.term i.issueArea, vce(cluster justiceName)
estat ic
eststo model3

*Amici Heterogeneity
logit bi_choicedv bi_certVote iddistance legalScores legalSalience ///
pubSalience resCoop frosh chiefJustice i.certDumb1 ///
dich_totsic i.term i.issueArea, vce(cluster justiceName)
estat ic
eststo model4

*full model
logit bi_choicedv i.bi_certVote iddistance legalScores legalSalience ///
pubSalience resCoop frosh chiefJustice i.certDumb1 ///
num_totBriefs i.dich_bcentTot i.dich_totsic i.term i.issueArea, vce(cluster justiceName)
estat ic
eststo model5

********************************************************
* Table 2 - Logistic Regression
capture log close  // Close any open logs
log using "regression_table.tex", text replace

esttab model1 model2 model3 model4 model5, se label booktabs ///
	cells("b" "se") ///
    title("Logistic Regression Model for Judicial Behavior, 1986-1994 Terms") ///
	style(tex)

log close

********************************************************	
*Figure 3 - Figure 3. Effect of Cert Decisions on non-consensual Behavior
*Figure 3a - Certiorari Vote
margins bi_certVote, atmeans predict(pr)
marginsplot, title("Certiorari Vote") ///
    ytitle("Probability of a Separate Opinion") xtitle("") ///
    xlabel(0 "Denied" 1 "Granted", angle(45) labsize(small)) ///
    plotopts(lcolor(black) lpattern(solid) lwidth(medium)) ///
    ciopts(lcolor(black) lpattern(dash)) ///
    graphregion(color(white)) ///
    yscale(range(0.25 0.5)) yscale(line)

*Figure 3b - Reasons for Cert
margins certDumb1, atmeans predict(pr)
marginsplot, title("Reasons for Cert") ///
    ytitle("Probability of a Separate Opinion") xtitle("") ///
    xlabel(0 "Other" 1 "Conflict" 2 "Important", angle(45) labsize(small)) ///
    plotopts(lcolor(black) lpattern(solid) lwidth(medium) mcolor(black) msymbol(circle) msize(medium)) ///
    ciopts(lcolor(black) lpattern(dash)) ///
    graphregion(color(white)) ///
    yscale(range(0.25 0.5)) yscale(line)

********************************************************
*Figure 4 - Effect of Number of Amicus Briefs on non-consensual Behavior
margins, at(num_totBriefs==(1(1)50)) vce(uncond)
marginsplot, title("") ///
    ytitle("Probability of a Separate Opinion") xtitle("Number of Amicus Briefs") ///
    plotopts(lcolor(black) lpattern(solid) lwidth(medium) mcolor(black) msymbol(circle) msize(medium)) ///
    ciopts(lcolor(black) lpattern(dash)) ///
    graphregion(color(white)) ///
    yscale(range(0 1)) yscale(line)

********************************************************
*Figure 5 - Effect of Heterogeneous Amicus on non-consensual Behavior
margins dich_totsic, atmeans predict(pr)
marginsplot, title("") ///
    ytitle("Probability of a Separate Opinion") xtitle("Amici Heterogeneity") ///
    plotopts(lcolor(black) lpattern(solid) lwidth(medium) mcolor(black) msymbol(circle) msize(medium)) ///
    ciopts(lcolor(black) lpattern(dash)) ///
    graphregion(color(white)) ///
    yscale(range(0.25 .5)) yscale(line)
	

********************************************************
*Appendix 1 - Table 1. Cross-tabulation of Cert Vote and on the Merits Disposition
tabulate bi_certVote vote, cell


********************************************************
*Appendix 2 - Table 2. Crosstabulation of Cert Vote and Reason for Cert
tabulate bi_certVote certDumb1, cell


********************************************************
*Appendix 3 - Table 3. Cross-tabulation of Cert Vote and Opinion by Justice
table (justiceName) (bi_certVote bi_choicedv), ///
	statistic(frequency)

********************************************************
*Appendix 4 - 
*Logistic Regression Models
*base model
logit majMin bi_certVote iddistance legalScores legalSalience ///
pubSalience resCoop frosh chiefJustice i.certDumb1 ///
i.term i.issueArea, vce(cluster justiceName)
estat ic 
eststo model1A

*Number of Amicus Briefs
logit majMin bi_certVote iddistance legalScores legalSalience ///
pubSalience resCoop frosh chiefJustice i.certDumb1 ///
num_totBriefs i.term i.issueArea , vce(cluster justiceName)
estat ic
eststo model2A

*Amici Power
logit majMin bi_certVote iddistance legalScores legalSalience ///
pubSalience resCoop frosh chiefJustice i.certDumb1 ///
dich_bcentTot i.term i.issueArea, vce(cluster justiceName)
estat ic
eststo model3A

*Amici Heterogeneity
logit majMin bi_certVote iddistance legalScores legalSalience ///
pubSalience resCoop frosh chiefJustice i.certDumb1 ///
dich_totsic i.term i.issueArea, vce(cluster justiceName)
estat ic
eststo model4A

*full model
logit majMin bi_certVote iddistance legalScores legalSalience ///
pubSalience resCoop frosh chiefJustice i.certDumb1 ///
num_totBriefs dich_bcentTot dich_totsic i.term i.issueArea, vce(cluster justiceName)
estat ic
eststo model5A

*Table 5. Models for Justice's Vote on the Merits, 1986-1994 Terms
capture log close  // Close any open logs
log using "appendix_5_regression_table.tex", text replace

esttab model1A model2A model3A model4A model5A, se label booktabs ///
	cells("b" "se") ///
    title("Logistic Regression Models for Justice's Vote on the Merits, 1986-1994 Terms") ///
	style(tex)

log close

********************************************************
**Appendix 5 - 
*Logistic Regression Models
*Number of Amicus Briefs
logit bi_choicedv iddistance legalScores legalSalience ///
pubSalience resCoop frosh chiefJustice i.certDumb1 ///
c.num_totBriefs##i.bi_certVote i.term i.issueArea , vce(cluster justiceName)
estat ic
eststo model1B

*Amici Power
logit bi_choicedv iddistance legalScores legalSalience ///
pubSalience resCoop frosh chiefJustice i.certDumb1 ///
i.dich_bcentTot##i.bi_certVote i.term i.issueArea, vce(cluster justiceName)
estat ic
eststo model2B

*Amici Heterogeneity
logit bi_choicedv iddistance legalScores legalSalience ///
pubSalience resCoop frosh chiefJustice i.certDumb1 ///
i.dich_totsic##i.bi_certVote i.term i.issueArea, vce(cluster justiceName)
estat ic
eststo model3B

*Table 6 - Interactive Models for Decision to Write/Join a Separate Opinion, 1986-1994 Terms
capture log close  // Close any open logs
log using "appendix_6_regression_table.tex", text replace

esttab model1B model2B model3B, se label booktabs ///
	cells("b" "se") ///
    title("Logistic Regression Interactive Models for Decision to Write/Join a Separate Opinion, 1986-1994 Terms") ///
	style(tex)

log close
